home *** CD-ROM | disk | FTP | other *** search
/ 10,000 Great Games / 10,000 Great Games.iso / Product / 66 / data1.cab / Source_Files / Src / Mstruct.cpp < prev    next >
C/C++ Source or Header  |  2000-01-16  |  2KB  |  102 lines

  1. #include "stdafx.h"
  2.  
  3. cMovingStructure::cMovingStructure(int x, int y, cProperties *orig)
  4.         : cStructure(x, y, orig)
  5. {    
  6.     current_waypoint = 0;
  7.  
  8.     waypoint_go_forward = TRUE;
  9.  
  10.     speed = 50;
  11. }
  12.  
  13. cMovingStructure::~cMovingStructure()
  14. {    
  15. }
  16.  
  17. void cMovingStructure::load(cParse *list)
  18. {
  19.     cStructure::load(list);
  20.  
  21.     speed = list->get_int("SPEED", 50);
  22. }
  23.  
  24. void cMovingStructure::save()
  25. {
  26.     cStructure::save();
  27.  
  28.     save_level_int("SPEED", speed);
  29. }
  30.  
  31. int cMovingStructure::control()
  32. {
  33.     // Call base class
  34.  
  35.     cStructure::control();
  36.  
  37.     // Move around
  38.  
  39.     fix d = waypoint_timer.delta() * speed;
  40.  
  41.     if (current_waypoint != 0)
  42.     {
  43.         if (square(d) >= (fix)d_square(x - current_waypoint->x, y - current_waypoint->y))
  44.         {
  45.             set_position(current_waypoint->x, current_waypoint->y);
  46.  
  47.             if (waypoint_go_forward)
  48.             {
  49.                 if (current_waypoint->next == 0)
  50.                 {
  51.                     current_waypoint = (cSpot *)current_waypoint->prev;
  52.  
  53.                     waypoint_go_forward = FALSE;
  54.                 }
  55.                 else
  56.                 {
  57.                     current_waypoint = (cSpot *)current_waypoint->next;
  58.                 }
  59.             }
  60.             else
  61.             {
  62.                 if (current_waypoint->prev == 0)
  63.                 {
  64.                     current_waypoint = (cSpot *)current_waypoint->next;
  65.  
  66.                     waypoint_go_forward = TRUE;
  67.                 }
  68.                 else
  69.                 {
  70.                     current_waypoint = (cSpot *)current_waypoint->prev;
  71.                 }
  72.             }
  73.         }
  74.         else
  75.         {
  76.             add_angular_position(d, angle(current_waypoint->x - x, current_waypoint->y - y));
  77.         }
  78.     }
  79.     else
  80.     {
  81.         current_waypoint = waypoints;
  82.     }
  83.  
  84.     // Move some stuff around
  85.  
  86.     move_objects_on_boundaries(line_bounds, players);
  87.     move_objects_on_boundaries(line_bounds, weapons);
  88.     move_objects_on_boundaries(line_bounds, bonus);
  89.  
  90.     // Check end lifetime
  91.  
  92.     return !explode && !below_screen();
  93. }
  94.  
  95. void cMovingStructure::create_editables(int select)
  96. {
  97.     new cEditableMovingStructure(this, select);
  98.     
  99.     for (cSpot *w = waypoints; w != 0; w = (cSpot *)w->next)
  100.         new cEditableMovingStructureWaypoint(this, w, select);
  101. }
  102.